-- 25.lua
-- Created by zouyb Jun/26/2015
-- 屠夫BUFF光效

return {
    onAppear = function(monster)   
        -- 当前怪物的基类ID
        local baseClassId = monster:query("base_class_id");

        -- 获取其他所有怪物
        local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();

        -- 是否有酒鬼
        local needAddBuf = false;

        for i = 1, #openMonsterGrids do
            local monsterGrid = openMonsterGrids[i];
            -- 如果酒鬼在场，需要播放“属性增益”光效
            if monsterGrid.gridData.monster:query("base_class_id") == 27 then
                needAddBuf = true;
            end            
        end

        if needAddBuf then
            -- 酒鬼在场，播放“属性增益”光效
            local monsterGrid = UIDungeonMgr:getCurLevel().grids[monster:getPos()];
            playAddBuffEffect(monsterGrid, BUFF_TYPE_ATTACK);
        end
	end,

    onDamaged = function(monster)    
	    -- 当前怪物的基类ID
		local baseClassId = monster:query("base_class_id");

        local monsterGrid = UIDungeonMgr:getCurLevel().grids[monster:getPos()];

		-- 当前血量
		local curHp = monster:getHp();
		local maxHp = monster:getMaxHp();
			
        if not monster:isDead() and curHp < maxHp / 2 and not monster.hasPlayedBuff then     
			playAddBuffEffect(monsterGrid, BUFF_TYPE_ATTACK);
			monster.hasPlayedBuff = true;
		end
    end,
};